<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
		$i=1;
		if(!isset($_SESSION['username']) || $_SESSION['username']==''){
			         //查询精华和置顶的新闻
					  $User = M("Tie"); 
					  $jing=1;
					  $ding=1;					 
					  $where['ding']=$ding;
					  $where['jing']=$jing;
                      $li = $User->where($where)->limit(3)->select();
					  $this->assign('li',$li);
			        
			          $message = D("tie"); 
		              $count= $message->count();// 查询满足要求的总记录数
					  $page= new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
					  $show= $page->show();// 分页显示输出
					  $arr = $message->limit($page->firstRow.','.$page->listRows)->select();
					  $this->assign('list',$arr);
					  $this->assign('show',$show);
					  $this->display('index2');//如果没登陆进入没头像的html
					
				}else{//用户本身数据
					$user=D("User");
					$where['id']=$_SESSION['uid'];
					$ar=$user->where($where)->find();
                    $this->assign('ar',$ar);//用户本身数据
					
					//查询精华和置顶的新闻
					  $User = M("Tie"); 
					  $jing=1;
					  $ding=1;					 
					  $where['ding']=$ding;
					  $where['jing']=$jing;
                      $li = $User->where($where)->limit(3)->select();
					  $this->assign('li',$li);

					  //关注
					
					 
			         $gz=M('Friends');
					 $where1['fid']=$_SESSION['uid'];		  
		             $data = M('user  as  a')->join('lt_friends  as  b  on b.cid = a.id')->field('username')->where($where1)->select();
					 $this->assign('data',$data);
					$this->display();//进入有头像的界面
			}
	}
	public function publish(){
		if(isset($_SESSION['username'])&& $_SESSION['username']!=''){
		    $user=M('User');
			$where['id']=$_SESSION['uid'];		
			$arr=$user->where($where)->find();		
			$exper=$arr['exper'];	
			$this->assign('exper',$exper);		
			$this->display();
		 }else{
			  $this->redirect('Index/index');
		 }
		
	}
		public function search(){
			if(isset($_SESSION['username'])&& $_SESSION['username']!=''){
			$a='%';
			$keywords = $a.$_POST['keyword'].$a;  //获取搜索关键字 
			$where['title|content'] = array('like',$keywords);  //用like条件搜索title和content两个字段 	
			$a = M('user  as  a')->join('lt_tie  as  b  on b.uid = a.id')->where($where)->select();
			$this->assign('a',$a);
			$this->display();
		 }else{
			  $this->redirect('Index/index');
		 }
		
	}
	public function hot(){
		//主页帖子分页
					$message = M("tie"); 
		            $count= $message->count();// 查询满足要求的总记录数
					$page= new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
					$show= $page->show();// 分页显示输出
					$arr = $message->limit($page->firstRow.','.$page->listRows)->select();
					$this->assign('list',$arr);
					$this->assign('show',$show);
		            $this->display();//进入有头像的界面
	}

}